/*
 * JobsQueue.cuh
 *
 *  Created on: Aug 2, 2013
 *      Author: jaime
 */

#ifndef JOBSQUEUE_CUH_
#define JOBSQUEUE_CUH_

#include "../Utils/GPUVec.cuh"
#include "Configs.cuh"
#include "../ErrorHandler/CudaMemoryErrorHandler.cuh"
#include <climits>

/**
 * A struct that represents a job and must always be on the device.
 * IMPORTANT: The Lit pointer must point to a vector on the device!
 *
 * number_of_literals = 0 -> end job: signal that there are not any more jobs.
 *
 */
struct Job
{
	Lit* literals;
	int number_of_literals;

};

__host__ Job mkJob_dev(Lit* literals, int number_of_literals);
__host__ __device__ void print_job(Job & job);

class JobsQueue {
private:
	GPUVec<Job> jobs;
	unsigned int* next_job_index;
	bool closed;
	unsigned int size_of_largest_job;

public:
	JobsQueue(int capacity);
	__device__ Job next_job();
	__host__ __device__ void close();
	__host__ void add(Job & job);
	__host__ __device__ int largest_job_size();
	__host__ __device__ int number_of_jobs();
	__host__ __device__ void print_jobs();
};
#endif /* JOBSQUEUE_CUH_ */

